﻿/*****************************************
 * 
 *  copyright (c) by ylshen
 * 
 *  author : ylshen (syl.lucky@gmail.com)
 *  
 *  created at : 08-05-21
 * 
 **************************************** */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using JYStockAnalyser.Model;
using JYStockAnalyser.Face;
using JYStockAnalyser.ClientLib;

namespace JYStockAnalyser.WinUI
{
    public partial class FrmChangePassword : Form
    {
        public FrmChangePassword()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string oldPassword = this.txtOldPassword.Text.Trim();
            string newPassword = this.txtPassword.Text.Trim();
            string reNewPassword = this.txtReNewPassword.Text.Trim();

            if (string.IsNullOrEmpty(oldPassword))
            {
                Tool.ShowInformationBox("请输入旧密码!");
                this.txtOldPassword.Focus();
                return;
            }
            if (string.IsNullOrEmpty(newPassword))
            {
                Tool.ShowInformationBox("请输入新密码!");
                this.txtPassword.Focus();
                return;
            }
            if (string.IsNullOrEmpty(reNewPassword))
            {
                Tool.ShowInformationBox("请重新输入新密码!");
                this.txtReNewPassword.Focus();
                return;
            }
            if (!oldPassword.Equals(CurrentInfo.User.Password))
            {
                Tool.ShowInformationBox("旧密码输入不正确!");
                this.txtOldPassword.Focus();
                return;
            }

            if (!newPassword.Equals(reNewPassword))
            {
                Tool.ShowInformationBox("两次密码输入不一致!");
                this.txtReNewPassword.Focus();
                return;
            }


            if (new UserManageFace().ChangePassword(CurrentInfo.User.UserName, newPassword) == 1)
            {
                Tool.ShowInformationBox("修改成功!");
                this.Close();
            }
            else
            {
                Tool.ShowInformationBox("修改失败!");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
